﻿
@{
    ViewData["Title"] = "BinSetIndex";
    Layout = null;
}

<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />

@* 查询条件 *@
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-sm3">
        <input type="text" name="binSetName" placeholder="库位名称" class="layui-input">
    </div>

    <button type="button" class="layui-btn layui-bg-blue" id="searchButton">查询</button>
    <button type="button" class="layui-btn">重置</button>

    <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom" onclick="addReturn()">
        新增
    </button>

</form>

@* 显示数据表格 *@
<table class="layui-hide" id="binSetData" lay-filter="binSetData" style="margin-top: 20px;margin-left: 20px">
</table>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="upd">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>

<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var form = layui.form;

        function show() {
            table.render({
                elem: '#binSetData',
                url: '/BinSet/GetBinSetList', // 实际接口地址

                page: true, // 开启分页
                limit: 10, // 每页默认显示的条数
                limits: [10, 20, 30], // 每页条数的选择项
                cols: [
                    [
                        { field: 'binSetCode', title: '库位编码', width: 120 },
                        { field: 'binSetName', title: '库位名称', width: 120 },
                        { field: 'binSetCapacity', title: '面积', width: 120 },
                        { field: 'binSetMax', title: '最大载重量', width: 120 },
                        { field: 'binSetUnitX', title: '库位位置X', width: 120 },
                        { field: 'binSetUnitY', title: '库位位置Y', width: 120 },
                        { field: 'binSetUnitZ', title: '库位位置Z', width: 120 },
                        {
                            field: 'isEnable',
                            title: '是否启用',
                            templet: function (d) {
                            return d.isEnable ? '是' : '否';
                        }
                        },
                        {
                            field: 'isFreeze',
                            title: '是否冻结',
                            templet: function (d) {
                            return '<input type="checkbox" ' + (d.isFreeze ? 'checked' : '') + ' name="isFreeze" lay-skin="switch" lay-filter="switchTest" title="是否">';
                        },
                            width: 110,
                            key: 'isFreeze'
                        },
                        { field: 'binSetResult', title: '备注', width: 120 },
                        { title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo' }
                    ]
                ],
                where: {
                    binSetName: $('#binSetName').val(),
                    areaCode:@ViewBag.areaCode
                },
                parseData: function (res) {
                    return {
                        code: res.code,
                        count: res.data.rowCount,
                        data: res.data.queryable
                    };
                },
            });
        }
        show();

        // 查询
        $("#searchButton").on("click", function () {
            show();
        });

        table.on('tool(binSetData)', function (obj) {
            var data = obj.data; // 获取当前行数据
            if (obj.event === 'delete') {

                layer.confirm('确定要删除吗？', {
                    btn: ['确定', '取消'] // 按钮
                }, function () {
                    $.ajax({
                    url: '/BinSet/BinSetDelete',
                        type: 'post',
                        data: {
                            id: data.id
                        },
                        success: function (res) {
                            if (res.msg == '删除成功') {
                                layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                    location.reload(); // 刷新页面
                                });
                            } else {
                                layer.msg(res.msg, { icon: 2, time: 1000 });
                            }
                        }
                    });
                }, function () {
                    layer.msg('已取消', { icon: 1, time: 1000 });
                });
            }
            if (obj.event === 'upd') {
                // iframe层
                layer.open({
                    type: 2,
                    title: '修改客户数据',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['600px', '60%'],
                    content: '/BinSet/BinSetUpdateIndex?id=' + data.id, // iframe的src
                    end: function () {
                        // iframe层关闭后刷新页面
                        location.reload(); // 刷新页面
                    }
                });
            }
  

        });
    });

         function addReturn() {
            console.log("添加仓库设置");
            // iframe层
            layer.open({
                type: 2,
                title: '添加仓库设置',
                shadeClose: true,
                shade: 0.5,
                area: ['600px', '60%'],
                content: '/BinSet/BinSetAddIndex', // iframe的src
                end: function () {
                    // iframe层关闭后刷新页面
                    location.reload(); // 刷新页面
                }
            });
        }
</script>


